package com.ztt.controller.admin;


import com.ztt.pojo.entity.zttPurchaseDetail;
import com.ztt.service.PurchaseDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class PurchaseDetailController {

    @Autowired
    private  PurchaseDetailService purchaseDetailService;

    @GetMapping("/selectAllPurchaseDetail")
    public List<zttPurchaseDetail> selectAllPurchaseDetail(){
        return purchaseDetailService.selectAllPurchaseDetail();
    }

    @PostMapping("/insertPurchaseDetail")
    public String insertPurchase(@RequestBody zttPurchaseDetail purchaseDetail){
        purchaseDetailService.insertPurchaseDetail(purchaseDetail);
        return "success";
    }

    @PostMapping("/getPurchaseDetailById")
    public zttPurchaseDetail getPurchaseDetailById(@RequestBody zttPurchaseDetail purchaseDetail) {
        return purchaseDetailService.getPurchaseDetailById(purchaseDetail);
    }

    @PostMapping("/getPurchaseDetailByProductId")
    public List<zttPurchaseDetail> getPurchaseDetailByProductId(@RequestBody zttPurchaseDetail purchaseDetail) {
        return purchaseDetailService.getPurchaseDetailByProductId(purchaseDetail);
    }

    @PostMapping("/getPurchaseDetailByPurchaseId")
    public List<zttPurchaseDetail> getPurchaseDetailByPurchaseId(@RequestBody zttPurchaseDetail purchaseDetail) {
        return purchaseDetailService.getPurchaseDetailByPurchaseId(purchaseDetail);
    }

    @PostMapping("/updatePurchaseDetail")
    public String updatePurchaseDetail(@RequestBody zttPurchaseDetail purchaseDetail) {
        purchaseDetailService.updatePurchaseDetail(purchaseDetail);
        return "success";
    }

    @PostMapping("/deletePurchaseDetail")
    public String deletePurchaseDetail(@RequestBody zttPurchaseDetail purchaseDetail) {
        try
        {

            purchaseDetailService.deletePurchaseDetail(purchaseDetail);
            return "success";
        }
        catch (Exception e)
        {
            return "error";
        }
    }

}
